<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-slide.css" />
    <style type="text/css">
        body {
            background: #f4f4f4;
            font-size:0.6rem;
            line-height: 1rem;
        }

        .bg-dark {
            background: #333333 !important;
        }

        .aui-slide-node img {
            width: auto;
            height: 100%;
        }
    </style>
</head>

<body>




    <div id="aui-slide3" >
        <div class="aui-slide-wrap" id="list1" >

          <!-- <div class="aui-slide-node bg-dark">
              <img   id="img1" src="" alt="">
          </div>
          <div class="aui-slide-node bg-dark">
              <img   id="img2" src="" alt="">
          </div>
          <div class="aui-slide-node bg-dark">
              <img   id="img3" src="" alt="">
          </div> -->
        </div>
      <div class="aui-slide-page-wrap" style="display:none">

        </div>
    </div>
    <section class="aui-grid">
        <img src="./img/index_1805021537362148.png" alt="">
    </section>
    <section class="aui-grid">
        <div class="aui-row" id="list">

        </div>
        <div class="push-status" id="pushStatus" style="text-align:center;margin:20px">上拉显示更多</div>
    </section>
</body>
<script type="text/template" id="template1">

    {{~it:value:index}}
    <div class="aui-slide-node bg-dark">
        <img  src="{{=urlImg(value.image)}}" alt="">
    </div>
    {{~}}
</script>
<script type="text/template" id="template">

    {{~it:value:index}}
    <div class="aui-col-xs-6 goods" style="padding:0 2px 5px;background:#f1f1f1" tapmode onclick="fnOpenWareWin('{{=value.id}},{{=value.source}}');">
       <div style="background-color:#ffffff">
        <img src="{{= fnSiteUrl(value.thumb)}}" alt="" width="200px" height="200px">
        <div class="aui-row" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;padding:0 10px;margin-top:0.3rem">
            {{= value.title}}<div class="aui-label aui-label-shike01">赠</div>
        </div>
        <p style="overflow:hidden;"><div class="aui-label aui-label-warning aui-label-outlined">包邮</div> <span style="text-decoration:line-through;color:#ff4285" style="font-size:0.5rem">{{= value.mod_price }}</span> &nbsp;&nbsp;&nbsp;
            <span style="font-size:0.6rem">仅剩{{= value.number}}份</span></p>
        </div>
    </div>
    {{~}}
</script>
<script type="text/javascript" src="../script/aui-slide.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>

<!--引入dot模板引擎-->
<script type="text/javascript" src="../script/doT.min.js"></script>


<script type="text/javascript">
    apiready = function() {
        fnUpdateSlide(); //发送请求加载数据分配到模板
        fnGetGoodsList(); //发送请求加载商品数据分配到模板
        initRefresh();
        initEventListenter();
        //addPushUp();//上啦加载；
    };

    //console.log(slide3.pageCount());

  function urlImg(src){
    var src1 = SITE_URL + src.substr(1);
    return src1;
  }

    count = "";
    page = 1;

    function fnGetGoodsList(load_more) {
        // api.showProgress({
        //     title: '努力加载中...',
        //     text: '先喝杯茶...',
        //     modal: false
        // });
        if (load_more) {
            page++;
        } else {
            page = 1;
        }
        api.ajax({
            //http://test.renqishike.com/index.php?m=api&c=appnew&a=goodslists&catid=0&is_point=0&is_vip=0&mod=trial&orderby=id&orderway=desc&page=1&trial_type=0
            url: SITE_URL + "index.php?m=api&c=appnew&a=goodslists&catid=0&is_point=0&is_vip=0&mod=trial&orderby=id&orderway=desc&page=" + page + "&trial_type=0",
            method: 'GET',
        }, function(ret, err) {
            if (ret.status == 1) {
                //每十条是一组数据；
                count = ret.count; //查到符合要求的数据总条数；
                pageTot = Math.ceil(count / 10);
                //判断总的页数
                //alert(count);
                //alert(pageTot);
                if (pageTot <= page) {
                    //如果大于；
                    var notice = $api.byId('pushStatus'); //获取节点
                    $api.html(notice, "没有啦！");
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    fnUpdateGoodsList(ret, load_more);
                } else {
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    fnUpdateGoodsList(ret, load_more);
                }
            } else {
                //api.refreshHeaderLoadDone(); //下拉刷新隐藏
                // api.alert({
                //     msg: JSON.stringify(err)
                // });
            }
        });
    }
    //数组分配到模板；
    function fnUpdateGoodsList1(ret) {
        //alert(JSON.stringify(ret));
        var list = $api.byId('list1'); //获取节点
        //var str={"array":["banana","apple","orange"]};
        // 1. 编译模板函数
        var tempFn = doT.template($api.byId('template1').innerHTML); //找到模板多次使用
        // 2. 多次使用模板函数
        var resultText = tempFn(ret);
        console.log(resultText);
       $api.html(list, "");
       $api.html(list, resultText);
        var slide3 = new auiSlide({
            container: document.getElementById("aui-slide3"),
            //  "width":300,
           "height": 178,
            "speed": 500,
            "autoPlay": 3000, //自动播放
            "loop": true,
            "pageShow": true,
            "pageStyle": 'line',
            'dotPosition': 'center'
        })
    }
    function fnUpdateGoodsList(ret, load_more) {

        var list = $api.byId('list'); //获取节点
        //var str={"array":["banana","apple","orange"]};
        // 1. 编译模板函数
        var tempFn = doT.template($api.byId('template').innerHTML); //找到模板多次使用
        // 2. 多次使用模板函数
        var resultText = tempFn(ret.lists);
        if (load_more) {
            $api.append(list, resultText);
        } else {
            $api.html(list, resultText);
        }
        api.hideProgress();
        //$api.html(list, resultText);
    }

    function fnUpdateSlide() {
        api.ajax({
            url: SITE_URL + 'index.php?m=api&c=appnew&a=focus&num=3&orderby=id&orderway=desc&type=1',
            method: 'GET',

        }, function(ret, err) {
        //  str = str; //删除第一个字符
    //  alert(JSON.stringify(ret));
      fnUpdateGoodsList1(ret);
            // var src3 = SITE_URL + ret[0].image.substr(1);
            // var src2 = SITE_URL + ret[1].image.substr(1);
            // var src1 = SITE_URL + ret[2].image.substr(1);
            // console.log(src1);
            // console.log(src2);
            // console.log(src3);
            // //alert(JSON.stringify(ret[0].image));
            // $("#img1").attr("src", src1);
            // $("#img2").attr("src", src2);
            // $("#img3").attr("src", src3);
            // var slide3 = new auiSlide({
            //     container: document.getElementById("aui-slide3"),
            //     // "width":300,
            //     "height": 200,
            //     "speed": 500,
            //     "autoPlay": 3000, //自动播放
            //     "loop": true,
            //     "pageShow": true,
            //     "pageStyle": 'line',
            //     'dotPosition': 'center'
            // });

        });

    }

    function fnUpdateBanner() {
        var banner = $api.byId('banner');
        api.imageCache({ //图片缓存，防止卡顿
            url: wareTypeList[api.pageParam.wareTypeIndex].banner.url
        }, function(ret, err) {
            if (ret) {
                //alert(JSON.stringify(ret));
                if (ret && ret.status) {
                    banner.src = ret.url;
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }
    //下拉刷新，松开刷新
    function initRefresh() {
        api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            fnGetGoodsList();
        });
    }



    //打开商品详情页面
    function fnOpenWareWin(wareId_) {
      //alert(wareId_);
      var strs=wareId_.split(","); //字符分割
        api.openWin({
            name: 'ware',
            url: './ware.html',
            pageParam: {
              wareId:strs[0],
              searchType:strs[1]
            },

        });
    }

    function initEventListenter() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 300
            }
        }, function(ret, err) {

            fnGetGoodsList(true);
        });
    }
</script>

</html>

</html>
